package com.cloud.wms.ui.returned.inventory;

import android.os.Bundle;
import android.os.Message;
import android.text.TextUtils;

import com.cloud.widget.ScanText;
import com.cloud.wms.R;
import com.cloud.wms.base.BaseBarActivity;
import com.cloud.wms.ui.returned.contact.InventoryContract;
import com.cloud.wms.ui.returned.entity.InventoryInfoEntity;
import com.cloud.wms.ui.returned.presenter.InventoryPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @Author： Chen
 * @Date： 2021/5/19
 * @Desc：
 */
public class ExpressActivity extends BaseBarActivity<InventoryPresenter> implements InventoryContract.View {
    @BindView(R.id.scan_text)
    ScanText scanText;

    @Override
    protected String barTitle() {
        return "退货清点";
    }

    @Override
    protected int getResId() {
        return R.layout.activity_returned_inventory_express;
    }

    @Override
    protected void setupComponent() {
        getActivityComponent().inject(this);
    }

    @Override
    protected void initEvent() {
        initScanText(scanText);
    }

    @Override
    protected void onScanHandle(String result, int resultCode) {
        super.onScanHandle(result, resultCode);
        scanText.addHistory(result);
        mPresenter.getReturnedInfo(result);
    }

    @Override
    public void onSuccess(Message message) {
        switch (message.what) {
            case InventoryPresenter.GET_RETURNED_COMMODITY:
                InventoryInfoEntity inventoryInfo = (InventoryInfoEntity) message.obj;
                boolean isHeadless = TextUtils.isEmpty(inventoryInfo.getShipOrderCode());
                if (!isHeadless && (inventoryInfo.getCommodityList() == null || inventoryInfo.getCommodityList().isEmpty())) {
                    info("当前退货快递单无可清点货物！");
                    return;
                }
                InventoryActivity.start(this, inventoryInfo);
                break;
        }
    }
}
